package com.haorui.lygyd.employeemanager.service;

import com.haorui.base.core.model.Search;
import com.haorui.base.core.service.BaseService;
import com.haorui.lygyd.employeemanager.entity.MemberEntity;
import com.haorui.lygyd.employeemanager.enumerate.JiesuanState;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.haorui.lygyd.employeemanager.entity.YuangongdingdanEntity;
import com.haorui.lygyd.employeemanager.repository.YuangongdingdanRepository;

import java.util.Date;
import java.util.List;

/**
 * @support: 西安鑫正豪信息技术有限公司
 * @author: 系统生成
 * @version: 1.0
 * @Date: Wed Feb 27 00:27:27 CST 2019
 * @Description: 员工订单
 */
@Slf4j
@Service
public class YuangongdingdanService extends BaseService<YuangongdingdanEntity,String> {
    private YuangongdingdanRepository yuangongdingdanRepository;
    public YuangongdingdanService(@Autowired YuangongdingdanRepository yuangongdingdanRepository) {
        super(yuangongdingdanRepository);
        this.yuangongdingdanRepository=yuangongdingdanRepository;
    }

    @Override
    protected Search<YuangongdingdanEntity> getSearch() {
        return new Search<YuangongdingdanEntity>(YuangongdingdanEntity.class);
    }
    public List<YuangongdingdanEntity> findbyYuangongId(String yuangongId)
    {
        return yuangongdingdanRepository.findAllByYuangongId(yuangongId);
    }

    public void jiesuanchenggong(String[] ids) {
        for (String id : ids) {
            YuangongdingdanEntity yuangongdingdanEntity = yuangongdingdanRepository.findOne(id);
            yuangongdingdanEntity.setJiesuanState(JiesuanState.JIESUAN_CHENGGONG);
            yuangongdingdanEntity.setJiesuanDate(new Date());
            yuangongdingdanRepository.save(yuangongdingdanEntity);
        }
    }
    public void jiesuanshibai(String[] ids) {
        for (String id : ids) {
            YuangongdingdanEntity yuangongdingdanEntity = yuangongdingdanRepository.findOne(id);
            yuangongdingdanEntity.setJiesuanState(JiesuanState.JIESUAN_SHIBAI);
            yuangongdingdanEntity.setJiesuanDate(new Date());
            yuangongdingdanRepository.save(yuangongdingdanEntity);
        }
    }
}
